package com.talent.study.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
 * @Author: hszhou
 * @Date: 2025/4/25 16:08
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Slf4j
public class ClientHandler extends ChannelInboundHandlerAdapter {


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {

        log.info("客户端连接成功");


        String req ="hello word$_";
        for (int i = 0; i < 100; i++) {
            ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
            byteBuf.writeBytes(req.getBytes(StandardCharsets.UTF_8));
            ctx.channel().writeAndFlush(byteBuf);
        }
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {



        super.channelRead(ctx, msg);
    }
}
